package com.wdb007.venus.svc.biz.manager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wdb007.venus.svc.dal.process.dao.ProcessInstructionLogDAO;

/**
 * 用来调用书格的开门API
 * @author lenovo
 *
 */
@Component("bookGridManager")
public class BookGridManager {

	private Logger logger = LoggerFactory.getLogger(BookGridManager.class);
	
	@Autowired
	private WSClientSenderBookShelf wsClientSenderBookShelf;
	@Autowired
	private WSClientSenderApp wsClientSenderApp;
	@Autowired
	private ProcessInstructionLogDAO processInstructionLogDAO;
	/**
	 * 通知书格进行操作： 开门、盘点
	 * @param gridCode
	 * @param gridTransId 
	 * @param action WSBookShelfEnum.unlock---开门      WSBookShelfEnum.single_stocktaking---盘点    WSBookShelfEnum.single_check_door  书格状态检查
	 */
	public void notifyBookGrid(String gridCode, Long gridTransId, WSBookShelfEnum action) {
		logger.info("通知书格[{}]进行 {}========{} 开始========", gridCode,action.name(), gridTransId);

		String transId = null ;
		if(null != gridTransId) {
			transId = gridTransId+"";
		}
		Long maxGroupId = null ;
		if(WSBookShelfEnum.bookgrid_check_req.equals(action) || WSBookShelfEnum.bookgrid_status_req.equals(action)) {
			maxGroupId = processInstructionLogDAO.getMaxGroupIdByGridCode(gridCode);
		}
		wsClientSenderBookShelf.send(gridCode, transId, action, maxGroupId);
		logger.info("通知书格[{}]进行{} ========{} 结束=====", gridCode,action.name(), gridTransId);
	
	}
	/**
	 * 通知APP书格开门状态
	 * @param gridCode
	 */
	public void notifyApp(long userid, String gridCode, String action) {
		logger.info("通知APP=====userid:{}, gridCode:{}, action:{} 开始发送", userid, gridCode, action);
		wsClientSenderApp.send(userid, gridCode, action);
		logger.info("通知APP=====userid:{}, gridCode:{}, action:{} 结束", userid, gridCode, action);
	}

	
	public static void main(String[] args) {
		BookGridManager manager = new BookGridManager();
		manager.notifyBookGrid("002120003001", 430L, WSBookShelfEnum.bookgrid_unlock_req);
	}
}
